<template>
  <el-form-item label="图片宽度">
    <el-input-number v-model="localData.width" controls-position="right" />
  </el-form-item>
  <el-form-item label="图片高度">
    <el-input-number v-model="localData.height" controls-position="right" />
  </el-form-item>
  <el-form-item label="显示图片来源">
    <el-cascader :props="CascaderProps" :options="attrList" v-model="localData.bindImgList" placeholder="请选择属性" filterable clearable :show-all-levels="false">
      <template #default="{ data: opt }">
        <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
      </template>
    </el-cascader>
  </el-form-item>
  <el-form-item label="图片标题">
    <el-input v-model="localData.imgLabel" />
  </el-form-item>
  <el-form-item label="显示模式">
    <el-select v-model="localData.viewType">
      <el-option label="缩略图" value="image" />
      <el-option label="缩略单图" value="single-image" />
      <el-option label="图文" value="label-image" />
      <el-option label="仅标题" value="label" />
    </el-select>
    <!-- <el-radio-group v-model="localData.viewType">
      <el-radio-button label="缩略图" value="" />
      <el-radio-button label="缩略单图" value="" />
      <el-radio-button label="图文" value="" />
      <el-radio-button label="仅标题" value="" />
    </el-radio-group> -->
  </el-form-item>
  <el-form-item label="图片标题位置">
    <el-radio-group v-model="localData.imgLabelPosition">
      <el-radio-button label="上" value="top" />
      <el-radio-button label="下" value="bottom" />
      <el-radio-button label="左" value="left" />
      <el-radio-button label="右" value="right" />
    </el-radio-group>
  </el-form-item>
  <el-form-item label="图片适应模式">
    <el-select v-model="localData.fit">
      <el-option label="原始" value="-" />
      <el-option label="拉伸" value="fill" />
      <el-option label="适配" value="contain" />
      <el-option label="覆盖" value="cover" />
      <el-option label="缩放" value="scale-down" />
    </el-select>
  </el-form-item>
  <el-form-item label="默认预览索引">
    <el-input-number v-model="localData.initialIndex" controls-position="right" />
  </el-form-item>
  <el-form-item label="关闭预览">
    <el-switch v-model="localData.withoutPreview" />
  </el-form-item>
  <el-form-item label="循环预览">
    <el-switch v-model="localData.infinite" />
  </el-form-item>
  <el-form-item label="查看缩放速率">
    <el-input-number v-model="localData.zoomRate" controls-position="right" />
  </el-form-item>
  <el-form-item label="最小缩放比例">
    <el-input-number v-model="localData.minScale" controls-position="right" />
  </el-form-item>
  <el-form-item label="最大缩放比例">
    <el-input-number v-model="localData.maxScale" controls-position="right" />
  </el-form-item>
</template>

<script>
export default {
  name: 'ImgViewerConfig',
  inheritAttrs: false,
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      localData: {},
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      }
    };
  },
  watch: {
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal;
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal);
      },
      deep: true
    }
  }
};
</script>